using System;
using System.IO;
using System.Windows.Forms;

namespace AStarTester
{
    public partial class frmMain : Form
    {
        private const string _DIRMAPSNAME = "Maps\\";

        public frmMain()
        {
            this.InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            foreach (string fileName in Directory.GetFiles(_DIRMAPSNAME, "*.lby", SearchOption.TopDirectoryOnly))
            {
                this.cmbMap.Items.Add(Path.GetFileNameWithoutExtension(fileName));
            }
            this.cmbMap.SelectedIndex = 1;
        }

        private void labyrinthe_SizeChanged(object sender, EventArgs e)
        {
            this.Size = new System.Drawing.Size(this.labyrinthe.Width + 50, this.labyrinthe.Height + 230);
        }

        private void btnFindPath_Click(object sender, EventArgs e)
        {
            this.labyrinthe.CalculateShortestPath();
            this.labyrinthe.DrawShortestPath();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            try
            {
                this.labyrinthe.LoadMap(string.Format("{0}{1}.lby", _DIRMAPSNAME, this.cmbMap.SelectedItem.ToString()));
            }
            catch
            {
                MessageBox.Show("Erreur lors du chargement !");
            }
        }
    }
}